package com.laan.bmagame;

import java.util.ArrayList;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;

public class Explosions {
	
	private ArrayList<Sprite> explosions;
//	private static final int NUVOLSMAX = 8;
//	private Random rand;
	Resources resources;
	BitmapFactory.Options options;
	
	public Explosions(Resources res) {
		explosions = new ArrayList<Sprite>();
//		rand = new Random();
		options = new BitmapFactory.Options();
		options.inPreferredConfig = Bitmap.Config.ARGB_8888;
		resources = res;
	}
	
	public void actualitza() {
//		toca_afegir();
		for(int i=explosions.size()-1; i>=0; i--) {
			Sprite explo = explosions.get(i);
			explo.actualitza();
			if(explo.finished) explosions.remove(i);
		}
	}
	
	public void draw(Canvas canvas) {
		for(Sprite o: explosions) o.draw(canvas);
	}
	
	public void afegir(float x, float y, float width, float height) {
		Bitmap explobmp = BitmapFactory.decodeResource(resources, R.drawable.explosionsprite, options);
		Sprite explo = new Sprite(explobmp, width, height, 24, 5, 5);
		explo.setCoords(x, y);
		explosions.add(explo);
		
//		if(explosions.size() == NUVOLSMAX) return;
//		for(int i=explosions.size(); i<NUVOLSMAX; i++) {
//			Bitmap nuvol;
//			if(rand.nextInt(2)==0) nuvol = BitmapFactory.decodeResource(resources, R.drawable.cloud1, options);
//			else nuvol = BitmapFactory.decodeResource(resources, R.drawable.cloud2, options);
//			float x,y,width,height,vx,vy;
//			width = (BASEWIDTH+(float)rand.nextInt(VARWIDTH))/1000*GV.Screen.metrics.widthPixels;
//			height = (BASEHEIGHT +(float)rand.nextInt(VARHEIGHT))/1000*GV.Screen.metrics.heightPixels;
//			y = (float)rand.nextInt(GV.Screen.metrics.heightPixels-(int)height);
//			vx = (BASEVX+(float)rand.nextInt(VARVX)/10000)*GV.Screen.metrics.widthPixels;
//			vy = 0;
//			if(rand.nextInt(2)==0) {
//				x = -width;
//			}
//			else {
//				x = GV.Screen.metrics.widthPixels;
//				vx = -vx;
//			}
//			explosions.add(new Objecte(nuvol,x,y,width,height,vx,vy));
//		}
	}
}
